﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq.Expressions;
namespace EllenTang.Bll
{
    public abstract class BaseBll<T>where T:class,new()
    {
        /// <summary>
        /// 获得DBSession实例,此实例中包含DAL中所有类的实例
        /// </summary>
        public IDal.IDBSession GetCurrentDbSession
        {
            get
            {
                return EllenTang.DalFactory.DBSessionFactory.DbSession;
            }
        }


        public IDal.IBaseDal<T> CurrentDal { get; set; }
        public abstract void SetCurretnDal();
        public BaseBll()
        {
            SetCurretnDal();
        }

        public IQueryable<T> LoadEntities(System.Linq.Expressions.Expression<Func<T, bool>> whereLamda)
        {
            return CurrentDal.LoadEntities(whereLamda);
        }

        public IQueryable<T> LoadEntities<s>(int pageSize, int pageIndex, out int pageCount, System.Linq.Expressions.Expression<Func<T, bool>> whereLamda, System.Linq.Expressions.Expression<Func<T, s>> orderbyLamda, bool isAsc)
        {
            return CurrentDal.LoadEntities<s>(pageSize, pageIndex, out pageCount, whereLamda, orderbyLamda, isAsc);
        }

        public bool UpdateEntities(T entities)
        {
            return CurrentDal.UpdateEntities(entities);
        }

        public bool DeleteEntities(T entities)
        {
            return CurrentDal.DeleteEntities(entities);
        }

        public T AddEntities(T entities)
        {
            return CurrentDal.AddEntities(entities);
        }

    }
}
